#include<bits/stdc++.h>
using namespace std;
#define f(a,b,c,d) for(int a=b;a<=c;a+=d)
int T,p[1000100];
int main(){
	freopen("color.in","r",stdin);
	freopen("color.out","w",stdout);
	scanf("%d",&T);
	while(T--){
		int d,n,x=-1,ans=0;
		memset(p,0,sizeof(p));
		scanf("%d",&n);
		f(i,1,n,1) scanf("%d",&d),p[d]++,x=max(x,d);
		f(i,1,x,1) if(p[i]!=0) ans+=(p[i]-1)*i;
		printf("%d\n",ans);
	}
	return 0;
}
